package view.user;

import common.RoomTypes;
import model.room.Room;
import model.room.RoomCount;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;
/*
 * Created by JFormDesigner on Tue May 28 15:44:00 HKT 2024
 */



/**
 * @author 11565
 */
public class RoomTypePanel extends JPanel {
    private Mainframe frame;
    public RoomTypePanel(Mainframe frame) {
        initComponents();
        this.frame = frame;
        table1.setModel(new UserRoomTableModel(frame.getStartTime(),frame.getEndTime()));
    }

    private void BackButton1(ActionEvent e) {
        // TODO add your code here
        frame.showTimePanel();
    }

    private void ConfrimButton2(ActionEvent e) {
        // TODO add your code here
        RoomTypes roomsType = null;
        int row = table1.getSelectedRow();
        if(row == 0){
            roomsType = RoomTypes.Single_ROOM;
        } else if(row == 1){
            roomsType = RoomTypes.Twin_ROOM;
        } else if (row == 2){
            roomsType = RoomTypes.Double_ROOM;
        } else if (row == 3) {
            roomsType = RoomTypes.Deluxe_ROOM;
        }
        frame.showFillInInformationPanel(roomsType);
    }

    private void flush(ActionEvent e) {
        // TODO add your code here
        table1.setModel(new UserRoomTableModel(frame.getStartTime(),frame.getEndTime()));
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - Qiqq
        panel1 = new JPanel();
        panel2 = new JPanel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        BackButton1 = new JButton();
        ConfrimButton2 = new JButton();
        flushButton = new JButton();

        //======== this ========
        setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.
        border.EmptyBorder(0,0,0,0), "JF\u006frmDes\u0069gner \u0045valua\u0074ion",javax.swing.border.TitledBorder.CENTER
        ,javax.swing.border.TitledBorder.BOTTOM,new java.awt.Font("D\u0069alog",java.awt.Font
        .BOLD,12),java.awt.Color.red), getBorder())); addPropertyChangeListener(
        new java.beans.PropertyChangeListener(){@Override public void propertyChange(java.beans.PropertyChangeEvent e){if("\u0062order"
        .equals(e.getPropertyName()))throw new RuntimeException();}});

        //======== panel1 ========
        {
            panel1.setLayout(new CardLayout());

            //======== panel2 ========
            {

                //======== scrollPane1 ========
                {
                    scrollPane1.setViewportView(table1);
                }

                //---- BackButton1 ----
                BackButton1.setText("\u8fd4\u56de");
                BackButton1.addActionListener(e -> BackButton1(e));

                //---- ConfrimButton2 ----
                ConfrimButton2.setText("\u786e\u8ba4");
                ConfrimButton2.addActionListener(e -> ConfrimButton2(e));

                //---- flushButton ----
                flushButton.setText("\u5237\u65b0");
                flushButton.addActionListener(e -> flush(e));

                GroupLayout panel2Layout = new GroupLayout(panel2);
                panel2.setLayout(panel2Layout);
                panel2Layout.setHorizontalGroup(
                    panel2Layout.createParallelGroup()
                        .addGroup(panel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(panel2Layout.createParallelGroup()
                                .addComponent(BackButton1)
                                .addComponent(ConfrimButton2)
                                .addComponent(flushButton))
                            .addContainerGap(7, Short.MAX_VALUE))
                );
                panel2Layout.setVerticalGroup(
                    panel2Layout.createParallelGroup()
                        .addGroup(panel2Layout.createSequentialGroup()
                            .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(panel2Layout.createSequentialGroup()
                            .addGap(133, 133, 133)
                            .addComponent(flushButton)
                            .addGap(43, 43, 43)
                            .addComponent(BackButton1)
                            .addGap(41, 41, 41)
                            .addComponent(ConfrimButton2)
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );
            }
            panel1.add(panel2, "card1");
        }

        GroupLayout layout = new GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup()
                .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - Qiqq
    private JPanel panel1;
    private JPanel panel2;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JButton BackButton1;
    private JButton ConfrimButton2;
    private JButton flushButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
